<?php

namespace app\user\model;

use think\Model;

class ShortUrlLog extends \app\common\model\ShortUrlLog
{

    protected $append = [
        'status_css',
        'scene_css',
        'format_expire_time',
        'status_text',
        'scene_text',
    ];

    public function getStatusCssAttr($value, $data)
    {

        if (isset($data['status']))
            return self::$statusCss[$data['status']];
    }

    public function getSceneCssAttr($value, $data)
    {
        if (isset($data['scene']))
            return self::$sceneCss[$data['scene']];
    }

    public function getFormatExpireTimeAttr($value, $data)
    {
        if (isset($data['expire_time'])) {
            if ($data['expire_time'] <= 0) {
                return '不过期';
            }
            return date('Y-m-d H:i', $data['expire_time']);
        }

    }

    public function getStatusTextAttr($value, $data)
    {
        if (isset($data['status'])) {
            return self::$status[$data['status']];
        }
    }

    public function getSceneTextAttr($value, $data)
    {
        if (isset($data['scene'])) {
            return self::$sceneMap[$data['scene']];
        }
    }

    public static function getTodaySetCount($userId)
    {
        return self::where('user_id', $userId)
            ->whereBetween('create_time', [strtotime(date('Y-m-d')), strtotime(date('Y-m-d 23:59:59'))])
            ->count();
    }

    public static function getAllCount($userId)
    {
        return self::where('user_id', $userId)
            ->count();
    }
}
